// 时间戳转时间
export function dateStrFromTimeStamp(interval: any, type: number) {
    if (interval === undefined || interval <= 0) {
      return 'NaN'
    }
    const time = parseInt(interval) * 1000
    const date = new Date(time)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const min = date.getMinutes()
  
    if (type === 1) {
      return `${year}-${fixTwoZeroNumber(month)}-${fixTwoZeroNumber(day)} ${fixTwoZeroNumber(hour)}:${fixTwoZeroNumber(min)}`
    }
  
    if (type === 2) {
      const nowDate = new Date()
      const nowYear = nowDate.getFullYear()
      const nowMonth = nowDate.getMonth() + 1
      const nowDay = nowDate.getDate()
      if (nowYear !== year) { // 往年
        return `${year}-${fixTwoZeroNumber(month)}-${fixTwoZeroNumber(day)} ${fixTwoZeroNumber(hour)}:${fixTwoZeroNumber(min)}`
      } else if (nowMonth !== month) { // 当年
        return `${fixTwoZeroNumber(month)}-${fixTwoZeroNumber(day)} ${fixTwoZeroNumber(hour)}:${fixTwoZeroNumber(min)}`
      } else if (nowDay !== day) { // 当月
        return `${fixTwoZeroNumber(month)}-${fixTwoZeroNumber(day)} ${fixTwoZeroNumber(hour)}:${fixTwoZeroNumber(min)}`
      } else { // 当天
        return `${fixTwoZeroNumber(hour)}:${fixTwoZeroNumber(min)}`
      }
    }
  
    return {
      year: year,
      month: month,
      day: day,
      hour: hour,
      min: min
    }
  }
  
  // 两位数数字， 前补0
  export function fixTwoZeroNumber(n: number) {
    return n >= 10 ? `${n}` : `0${n}`
  }
  